package com.youlai.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.youlai.system.model.entity.AttendanceLeaveSetting;
import com.youlai.system.mapper.AttendanceLeaveSettingMapper;
import com.youlai.system.model.form.AttendanceLeaveSettingForm;
import com.youlai.system.service.IAttendanceLeaveSettingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.Data;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 只茂瑞
 * @since 2024-06-23
 */
@Service
@Data
public class AttendanceLeaveSettingServiceImpl extends ServiceImpl<AttendanceLeaveSettingMapper, AttendanceLeaveSetting> implements IAttendanceLeaveSettingService {

    private final AttendanceLeaveSettingMapper attendanceLeaveSettingMapper;

    @Override
    public List<AttendanceLeaveSettingForm> getLeaveSettingForm(Long id) {
        QueryWrapper<AttendanceLeaveSetting> queryWrapper = new QueryWrapper<AttendanceLeaveSetting>()
                .select("id","leave_type","department_id","name","is_enable")
                .eq("department_id",id);
        List<AttendanceLeaveSetting> attendanceLeaveSettings = attendanceLeaveSettingMapper.selectList(queryWrapper);
        System.out.println(attendanceLeaveSettings);
        List<AttendanceLeaveSettingForm> attendanceLeaveSettingForms = new ArrayList<>();
        for (AttendanceLeaveSetting setting : attendanceLeaveSettings) {
            AttendanceLeaveSettingForm form = new AttendanceLeaveSettingForm();
            BeanUtil.copyProperties(setting, form); // 假设您使用的是 Hutool 的 BeanUtil
            attendanceLeaveSettingForms.add(form);
        }
        System.out.println(attendanceLeaveSettingForms);
        return attendanceLeaveSettingForms;
    }

    @Override
    public Integer updateAttendUpdateLeaveStatus(AttendanceLeaveSettingForm attendanceLeaveSettingForm) {
        attendanceLeaveSettingMapper.updateEnable(attendanceLeaveSettingForm);
        return attendanceLeaveSettingForm.getId();
    }
}
